import { Form, Input, InputNumber, DatePicker } from "antd";
import { useEffect, useState } from "react";
import { message } from "antd";
import { Switch } from "antd";
import { licenseDetail } from "../service";
import dayjs from "dayjs";

const LicenseFormMgr = ({ record, formRef }) => {
    const { TextArea } = Input;

    const tryLoadLicense = async () => {
        if(record?.id){
            let licenseInfo = await licenseDetail({id: record.id});
            licenseInfo.effectiveTime = dayjs(licenseInfo.effectiveTime)
            licenseInfo.expireTime = dayjs(licenseInfo.expireTime)
            console.log(licenseInfo)
            formRef.current.setFieldsValue(licenseInfo);
        }
    }

    useEffect(() => {
        tryLoadLicense();
    }, []);

    return (
        <>
            <Form.Item
                label="License名称"
                name="licenseName"
                rules={[
                    {
                        required: true,
                        message: '请输入License名称',
                    }, { type: 'string', max: 32 }
                ]}
            >
                <Input placeholder='请输入License名称' autoComplete="off" />
            </Form.Item>

            <Form.Item
                label="状  态"
                name="enableState"
            >
                <Switch />
            </Form.Item>

            <Form.Item
                label="生效时间"
                name="effectiveTime"
                rules={[
                    {
                        required: true,
                        message: '请输入生效时间',
                    }
                ]}
            >
                <DatePicker
                    showTime={{ format: 'HH:mmm' }}
                    format="YYYY-MM-DD HH:mm"
                />
            </Form.Item>

            <Form.Item
                label="过期时间"
                name="expireTime"
                rules={[
                    {
                        required: true,
                        message: '请输入过期时间',
                    }
                ]}
            >
                <DatePicker
                    showTime={{ format: 'HH:mmm' }}
                    format="YYYY-MM-DD HH:mm"
                />
            </Form.Item>

            <Form.Item
                label="白名单"
                name="whiteIps"
            >
                <TextArea
                    showCount
                    maxLength={100}
                    placeholder="请输入Ip白名称,以逗号分隔"
                    style={{ height: 120, resize: 'none' }}
                />
            </Form.Item>

            <Form.Item
                label="黑名单"
                name="blackIps"
            >
                <TextArea
                    showCount
                    maxLength={100}
                    placeholder="请输入Ip黑名单,以逗号分隔"
                    style={{ height: 120, resize: 'none' }}
                />
            </Form.Item>
            <Form.Item
                label="备注"
                name="notes"
            >
                <TextArea
                    showCount
                    maxLength={100}
                    placeholder="请输入备注信息"
                    style={{ height: 120, resize: 'none' }}
                />
            </Form.Item>
        </>
    );

}

export default LicenseFormMgr;